package com.xufeng.demo.test;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 使用函数式编程实现设计模式
 * 责任装饰器
 *
 * @author xufeng
 * @since 21.07.2023
 */
public class main3 {

    Consumer<String> toASCII = x -> System.out.println("Print ASCII: " + x);

    Function<String, String> toHex = x -> x.chars().boxed().map(y -> "0x" + Integer.toHexString(y))
            .collect(Collectors.joining(" "));

    Consumer<String> decorateToHex = x -> System.out.println("Print HEX: " + toHex.apply(x));


    public static void main(String[] args) {
        main3 m = new main3();
        m.toASCII.andThen(m.decorateToHex).accept("text");
    }


}
